package com.tron.sync.controller;

import com.tron.sync.commons.BaseController;
import com.tron.sync.entities.WpsUser;
import com.tron.sync.service.WpsServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * edit 1
 */

@Api(tags = "WPS平台用户")
@RestController
public class WpsController extends BaseController {

    @Autowired
    WpsServiceImpl wpsServiceImpl;


    @ApiOperation(value = "获取用户信息")
    @GetMapping("/getUser")
    public Object getUser(String syndaUserId) {
        WpsUser result = wpsServiceImpl.getUser(syndaUserId);
        HashMap<String, Object> hashMap = new HashMap<>();
        if (null == result) {
            hashMap.put("state", 500);
            hashMap.put("message", "用户还未同步到wps平台");
            return hashMap;
        }
        hashMap.put("state", 200);
        hashMap.put("data", result);
        return hashMap;
    }


    @ApiOperation(value = "同步单个synda用户到wps ",notes = "传参: syndaUserId userName cardNo syndaOrgId")
    @GetMapping("/addSyndaUserToWps")
    public Object addSyndaUserToWps(WpsUser  wpsUser) {
        WpsUser result = wpsServiceImpl.addCompanyUser(wpsUser);
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("state", 200);
        hashMap.put("data", result);
        return hashMap;
    }

    @ApiOperation(value = "删除指定部门============注意！该结构会级联删除子部门及用户")
    @GetMapping("/deepDeleteDept")
    public String deepDeleteDept(String syndaOrgId) {
        String result = wpsServiceImpl.deepDeleteDept(syndaOrgId);
        return result;
    }



    @ApiOperation(value = "获取wpsToken")
    @GetMapping("/getWpsToken")
    public String getWpsToken() {
        String token = wpsServiceImpl.getToken();
        return token;
    }
}
